<template>
	<view class="loginContainer">
		<image class="header-img" :src="avatarUrl" mode=""></image>
		<view class="ipt">
			<text>
				用户名：
			</text>
			<input type="nickname" class="weui-input" :value="nickName" @blur="bindblur" placeholder="请输入昵称" />
		</view>

		<view class="btn-login">
			<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				微信登录
			</button>
		</view>


	</view>
</template>

<script>
	const defaultAvatarUrl =
		'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

	export default {
		data() {
			return {
				avatarUrl: defaultAvatarUrl,
				nickName: '',
				userInfo: {}
			}
		},
		methods: {
			// 获取头像方法
			onChooseAvatar(e) {
				this.avatarUrl = e.detail.avatarUrl;
				this.userInfo = {
					avatarUrl: this.avatarUrl,
					nickName: this.nickName
				}
				if (e.detail.avatarUrl) {
					uni.setStorage({
						key: 'userInfo',
						data: this.userInfo
					})

					// 跳转到user页面
					uni.reLaunch({
						url: '/pages/user/user'
					})
				}

			},
			handleGetPhoneNumber(e) {
				console.log(e);
			},
			// 获取昵称方法
			bindblur(e) {
				this.nickName = e.detail.value

			}

		}
	}
</script>

<style lang="scss">
	.loginContainer {
		.header-img {
			display: block;
			margin: 100rpx auto;
			width: 100rpx;
			height: 100rpx;
			border-radius: 999rpx;
			// border: 1rpx solid red;
			overflow: hidden;
		}

		.avatar-wrapper {
			margin: 0 auto;
			margin-top: 120rpx;
		}

		.ipt {
			display: flex;
			align-items: center;
			margin: 20rpx 20rpx;
			.weui-input{
				padding: 0 40rpx;
				width:500rpx;
				height: 80rpx;
				line-height: 80rpx;
				border-radius: 999rpx;
				background: #f7f1f1;
			}
		}

		.btn-login {
			display: flex;
			justify-content: space-around;

			.avatar-wrapper {
				background: green;
				color: #fff;
			}

		}
	}
</style>
